let json2xml = require('pt-core-common').util.json2xml;
let feedsTemplate = require('./feeds.templates.func');

let feedsRelationshipsTemplate = {
    messageListTemplate: function(operationType, relationshipsList){ // relationshipsList = {ParentSKU: xxx, Relation: {ShipOption: "xyz", IsShippingRestricted: true, Type: Additive, ShipAmount: 29.99}}
        let messageList = [];
        let index = 0;
        relationshipsList.forEach(relationship => {
            index++;
            messageList.push(Object.assign({
                MessageID: index,
                OperationType: operationType
            }, relationship))
        });
        return messageList;
    },
    amazonEnvelopeTemplate2xml: function(sellerId, operationType, relationshipsList){
        const messageList = feedsRelationshipsTemplate.messageListTemplate(operationType, relationshipsList);
        return json2xml("AmazonEnvelope", feedsTemplate.amazonEnvelopeTemplate(sellerId, "Relationship", messageList));
    }
};

module.exports = feedsRelationshipsTemplate;